@using GraphQL
@model Lombiq.JsonEditor.ViewModels.DisplayJsonFieldViewModel

@{
    var name = (Model.PartFieldDefinition.PartDefinition.Name + Model.PartFieldDefinition.Name).ToCamelCase();
    var safeJson = JsonNode.Parse(Model.Value ?? "{}")?.ToString() ?? "{}";
}

@* This exposes the field value to the client JavaScript. Re-parsing the JSON into JObject ensures that there is no
    dangerous content (such as JS code injection) in there, so it's safe to pass the value into Html.Raw(). *@
<script>
    if (!('JsonField' in window) || !window.JsonField) window.JsonField = {};
    const fieldName = @name.JsonHtmlContent();
    window.JsonField[fieldName] = @Html.Raw(safeJson);
</script>
